/* $Id: PageProblems.java 138 2011-09-01 17:51:37Z altdotua@gmail.com $ */

package alt.djudge.frontend.client.ui.contest;

import alt.djudge.frontend.client.ui.AsyncCallbackSucc;
import alt.djudge.frontend.client.ui.ContentPage;
import alt.djudge.frontend.shared.dto.contest.ContestProblemInfoDTO;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.VerticalPanel;


public class PageProblems extends FlowPanel implements ContentPage
{
	public PageProblems()
	{
	}
	
	public void onDataLoaded(ContestProblemInfoDTO[] data)
	{
		clear();
		add(new HTML("<h1>Problems list</h1>"));
		VerticalPanel panel = new VerticalPanel();
		for (ContestProblemInfoDTO problem : data)
		{
			panel.add(new Hyperlink(problem.getSid() + ": " + problem.getName(), "contest-" + Layout.getLayout().getContestId() + "/problem-" + problem.getId()));
		}
		add(panel);
	}
	
	public void loadData()
	{
		AsyncCallback<ContestProblemInfoDTO[]> callback = Layout.getLayout().getAsyncCallback(new AsyncCallbackSucc<ContestProblemInfoDTO[]>()
		{
			@Override
			public void onSuccess(ContestProblemInfoDTO[] result)
			{
				onDataLoaded(result);
			}
		});
		Layout.contestService.getProblems(Layout.getLayout().getContestId(), callback);
	}

	@Override
	public void dispatch(String token)
	{
		loadData();
	}

	@Override
	public String getHistoryTokenPrefix()
	{
		return "problems";
	}
}

